#include <ebase/types.h>
#include <ebase/trace.h>
#include <ebase/builtins.h>

#include <common/return_codes.h>

#include "isi.h"
#include "isi_iss.h"
#include "isi_priv.h"
#include "OV2686_priv.h"
#define P977 1

/*****************************************************************************
 * DEFINES
 *****************************************************************************/


/*****************************************************************************
 * GLOBALS
 *****************************************************************************/

// Image sensor register settings default values taken from data sheet OV8810_DS_1.1_SiliconImage.pdf.
// The settings may be altered by the code in IsiSetupSensor.
const IsiRegDescription_t OV2686_g_aRegDescription[] =
{
    {0x3000, 0x03,"",eReadWrite},
    {0x3001, 0xff,"",eReadWrite},
    {0x3002, 0x1a,"",eReadWrite},
    {0x3011, 0x03,"",eReadWrite},
    {0x301d, 0xf0,"",eReadWrite},
    {0x3020, 0x00,"",eReadWrite},
    {0x3021, 0x23,"",eReadWrite},
    {0x3082, 0x2c,"",eReadWrite},
    {0x3083, 0x00,"",eReadWrite},
    {0x3084, 0x07,"",eReadWrite},
    {0x3085, 0x03,"",eReadWrite},
    {0x3086, 0x00,"",eReadWrite},
    {0x3087, 0x00,"",eReadWrite},
    {0x3106, 0x01,"",eReadWrite},
    {0x3501, 0x26,"",eReadWrite},
    {0x3502, 0x40,"",eReadWrite},
    {0x3503, 0x03,"",eReadWrite},
    {0x350b, 0x36,"",eReadWrite},
    {0x3600, 0xb4,"",eReadWrite},
    {0x3603, 0x35,"",eReadWrite},
    {0x3604, 0x24,"",eReadWrite},
    {0x3605, 0x00,"",eReadWrite},
    {0x3620, 0x25,"",eReadWrite},
    {0x3621, 0x37,"",eReadWrite},
    {0x3622, 0x23,"",eReadWrite},
    {0x3628, 0x10,"",eReadWrite},
    {0x3701, 0x64,"",eReadWrite},
    {0x3705, 0x3c,"",eReadWrite},
    {0x370a, 0x23,"",eReadWrite},
    {0x370c, 0x50,"",eReadWrite},
    {0x370d, 0xc0,"",eReadWrite},
    {0x3717, 0x58,"",eReadWrite},
    {0x3718, 0x80,"",eReadWrite},
    {0x3720, 0x00,"",eReadWrite},
    {0x3721, 0x00,"",eReadWrite},
    {0x3722, 0x00,"",eReadWrite},
    {0x3723, 0x00,"",eReadWrite},
    {0x3738, 0x00,"",eReadWrite},
    {0x3781, 0x80,"",eReadWrite},
    {0x3789, 0x60,"",eReadWrite},
    {0x3800, 0x00,"",eReadWrite},
    {0x3801, 0x00,"",eReadWrite},
    {0x3802, 0x00,"",eReadWrite},
    {0x3803, 0x00,"",eReadWrite},
    {0x3804, 0x06,"",eReadWrite},
    {0x3805, 0x4f,"",eReadWrite},
    {0x3806, 0x04,"",eReadWrite},
    {0x3807, 0xbf,"",eReadWrite},
    {0x3808, 0x03,"",eReadWrite},
    {0x3809, 0x20,"",eReadWrite},
    {0x380a, 0x02,"",eReadWrite},
    {0x380b, 0x58,"",eReadWrite},
    {0x3810, 0x00,"",eReadWrite},
    {0x3811, 0x04,"",eReadWrite},
    {0x3812, 0x00,"",eReadWrite},
    {0x3813, 0x04,"",eReadWrite},
    {0x3814, 0x31,"",eReadWrite},
    {0x3815, 0x31,"",eReadWrite},
    {0x3820, 0xc2,"",eReadWrite},
    {0x3821, 0x01,"",eReadWrite},
    {0x380c, 0x6,"",eReadWrite},
    {0x380d, 0xa4,"",eReadWrite},
    {0x380e, 0x05,"",eReadWrite},
    {0x380f, 0x0e,"",eReadWrite},
    {0x3a02, 0x90,"",eReadWrite},
    {0x3a06, 0x00,"",eReadWrite},
    {0x3a07, 0xc2,"",eReadWrite},
    {0x3a08, 0x00,"",eReadWrite},
    {0x3a09, 0xa1,"",eReadWrite},
    {0x3a0e, 0x02,"",eReadWrite},
    {0x3a0f, 0x46,"",eReadWrite},
    {0x3a10, 0x02,"",eReadWrite},
    {0x3a11, 0x84,"",eReadWrite},
    {0x3a00, 0x43,"",eReadWrite},
    {0x382a, 0x08,"",eReadWrite},
    {0x3a0a, 0x07,"",eReadWrite},
    {0x3a0b, 0x8c,"",eReadWrite},
    {0x3a0c, 0x07,"",eReadWrite},
    {0x3a0d, 0x8c,"",eReadWrite},
    {0x4000, 0x81,"",eReadWrite},
    {0x4001, 0x40,"",eReadWrite},
    {0x4008, 0x00,"",eReadWrite},
    {0x4009, 0x03,"",eReadWrite},
    {0x4300, 0x32,"",eReadWrite},
    {0x430e, 0x00,"",eReadWrite},
    {0x4602, 0x02,"",eReadWrite},
    {0x5000, 0xff,"",eReadWrite},
    {0x5001, 0x05,"",eReadWrite},
    {0x5002, 0x32,"",eReadWrite},
    {0x5003, 0x04,"",eReadWrite},
    {0x5004, 0xff,"",eReadWrite},
    {0x5005, 0x12,"",eReadWrite},
    {0x3784, 0x08,"",eReadWrite},
    {0x5180, 0xf4,"",eReadWrite},
    {0x5181, 0x11,"",eReadWrite},
    {0x5182, 0x41,"",eReadWrite},
    {0x5183, 0x42,"",eReadWrite},
    {0x5184, 0x6e,"",eReadWrite},
    {0x5185, 0x56,"",eReadWrite},
    {0x5186, 0xb4,"",eReadWrite},
    {0x5187, 0xb2,"",eReadWrite},
    {0x5188, 0x08,"",eReadWrite},
    {0x5189, 0x0e,"",eReadWrite},
    {0x518a, 0x0e,"",eReadWrite},
    {0x518b, 0x46,"",eReadWrite},
    {0x518c, 0x38,"",eReadWrite},
    {0x518d, 0xf8,"",eReadWrite},
    {0x518e, 0x04,"",eReadWrite},
    {0x518f, 0x7f,"",eReadWrite},
    {0x5190, 0x40,"",eReadWrite},
    {0x5191, 0x5f,"",eReadWrite},
    {0x5192, 0x40,"",eReadWrite},
    {0x5193, 0xff,"",eReadWrite},
    {0x5194, 0x40,"",eReadWrite},
    {0x5195, 0x07,"",eReadWrite},
    {0x5196, 0x04,"",eReadWrite},
    {0x5197, 0x04,"",eReadWrite},
    {0x5198, 0x00,"",eReadWrite},
    {0x5199, 0x05,"",eReadWrite},
    {0x519a, 0xd2,"",eReadWrite},
    {0x519b, 0x04,"",eReadWrite},
    {0x5200, 0x09,"",eReadWrite},
    {0x5201, 0x00,"",eReadWrite},
    {0x5202, 0x06,"",eReadWrite},
    {0x5203, 0x20,"",eReadWrite},
    {0x5204, 0x41,"",eReadWrite},
    {0x5205, 0x16,"",eReadWrite},
    {0x5206, 0x00,"",eReadWrite},
    {0x5207, 0x05,"",eReadWrite},
    {0x520b, 0x30,"",eReadWrite},
    {0x520c, 0x75,"",eReadWrite},
    {0x520d, 0x00,"",eReadWrite},
    {0x520e, 0x30,"",eReadWrite},
    {0x520f, 0x75,"",eReadWrite},
    {0x5210, 0x00,"",eReadWrite},
    {0x5280, 0x14,"",eReadWrite},
    {0x5281, 0x02,"",eReadWrite},
    {0x5282, 0x02,"",eReadWrite},
    {0x5283, 0x04,"",eReadWrite},
    {0x5284, 0x06,"",eReadWrite},
    {0x5285, 0x08,"",eReadWrite},
    {0x5286, 0x0c,"",eReadWrite},
    {0x5287, 0x10,"",eReadWrite},
	
    {0x5300, 0xc5,"",eReadWrite},
    {0x5301, 0xa0,"",eReadWrite},
    {0x5302, 0x05,"",eReadWrite},
    {0x5303, 0x05,"",eReadWrite},
    {0x5304, 0x05,"",eReadWrite},
    {0x5305, 0x05,"",eReadWrite},
    {0x5306, 0x05,"",eReadWrite},
    {0x5307, 0x05,"",eReadWrite},
	
    {0x5308, 0x82,"",eReadWrite},
    {0x5309, 0x00,"",eReadWrite},
    {0x530a, 0x26,"",eReadWrite},
    {0x530b, 0x02,"",eReadWrite},
    {0x530c, 0x02,"",eReadWrite},
    {0x530d, 0x00,"",eReadWrite},
    {0x530e, 0x0c,"",eReadWrite},
    {0x530f, 0x14,"",eReadWrite},
    {0x5310, 0x1a,"",eReadWrite},
    {0x5311, 0x20,"",eReadWrite},
    {0x5312, 0x80,"",eReadWrite},
    {0x5313, 0x4b,"",eReadWrite},
	
    {0x5380, 0x01,"",eReadWrite},
    {0x5381, 0x0c,"",eReadWrite},
    {0x5382, 0x00,"",eReadWrite},
    {0x5383, 0x16,"",eReadWrite},
    {0x5384, 0x00,"",eReadWrite},
    {0x5385, 0xb3,"",eReadWrite},
    {0x5386, 0x00,"",eReadWrite},
    {0x5387, 0x7e,"",eReadWrite},
    {0x5388, 0x00,"",eReadWrite},
    {0x5389, 0x07,"",eReadWrite},
    {0x538a, 0x01,"",eReadWrite},
    {0x538b, 0x35,"",eReadWrite},
    {0x538c, 0x00,"",eReadWrite},
    {0x5400, 0x0d,"",eReadWrite},
    {0x5401, 0x18,"",eReadWrite},
    {0x5402, 0x31,"",eReadWrite},
    {0x5403, 0x5a,"",eReadWrite},
    {0x5404, 0x65,"",eReadWrite},
    {0x5405, 0x6f,"",eReadWrite},
    {0x5406, 0x77,"",eReadWrite},
    {0x5407, 0x80,"",eReadWrite},
    {0x5408, 0x87,"",eReadWrite},
    {0x5409, 0x8f,"",eReadWrite},
    {0x540a, 0xa2,"",eReadWrite},
    {0x540b, 0xb2,"",eReadWrite},
    {0x540c, 0xcc,"",eReadWrite},
    {0x540d, 0xe4,"",eReadWrite},
    {0x540e, 0xf0,"",eReadWrite},
    {0x540f, 0xa0,"",eReadWrite},
    {0x5410, 0x6e,"",eReadWrite},
    {0x5411, 0x06,"",eReadWrite},
    {0x5480, 0x19,"",eReadWrite},
    {0x5481, 0x00,"",eReadWrite},
    {0x5482, 0x09,"",eReadWrite},
    {0x5483, 0x12,"",eReadWrite},
    {0x5484, 0x04,"",eReadWrite},
    {0x5485, 0x06,"",eReadWrite},
    {0x5486, 0x08,"",eReadWrite},
    {0x5487, 0x0c,"",eReadWrite},
    {0x5488, 0x10,"",eReadWrite},
    {0x5489, 0x18,"",eReadWrite},
    {0x5500, 0x02,"",eReadWrite},
    {0x5501, 0x03,"",eReadWrite},
    {0x5502, 0x04,"",eReadWrite},
    {0x5503, 0x05,"",eReadWrite},
    {0x5504, 0x06,"",eReadWrite},
    {0x5505, 0x08,"",eReadWrite},
    {0x5506, 0x00,"",eReadWrite},
    {0x5600, 0x02,"",eReadWrite},
    {0x5603, 0x40,"",eReadWrite},
    {0x5604, 0x28,"",eReadWrite},
    {0x5609, 0x20,"",eReadWrite},
    {0x560a, 0x60,"",eReadWrite},
    {0x5780, 0x3e,"",eReadWrite},
    {0x5781, 0x0f,"",eReadWrite},
    {0x5782, 0x04,"",eReadWrite},
    {0x5783, 0x02,"",eReadWrite},
    {0x5784, 0x01,"",eReadWrite},
    {0x5785, 0x01,"",eReadWrite},
    {0x5786, 0x00,"",eReadWrite},
    {0x5787, 0x04,"",eReadWrite},
    {0x5788, 0x02,"",eReadWrite},
    {0x5789, 0x00,"",eReadWrite},
    {0x578a, 0x01,"",eReadWrite},
    {0x578b, 0x02,"",eReadWrite},
    {0x578c, 0x03,"",eReadWrite},
    {0x578d, 0x03,"",eReadWrite},
    {0x578e, 0x08,"",eReadWrite},
    {0x578f, 0x0c,"",eReadWrite},
    {0x5790, 0x08,"",eReadWrite},
    {0x5791, 0x04,"",eReadWrite},
    {0x5792, 0x00,"",eReadWrite},
    {0x5793, 0x00,"",eReadWrite},
    {0x5794, 0x03,"",eReadWrite},
    {0x5800, 0x03,"",eReadWrite},
    {0x5801, 0x14,"",eReadWrite},
    {0x5802, 0x02,"",eReadWrite},
    {0x5803, 0x64,"",eReadWrite},
    {0x5804, 0x1e,"",eReadWrite},
    {0x5805, 0x05,"",eReadWrite},
    {0x5806, 0x2a,"",eReadWrite},
    {0x5807, 0x05,"",eReadWrite},
    {0x5808, 0x03,"",eReadWrite},
    {0x5809, 0x17,"",eReadWrite},
    {0x580a, 0x02,"",eReadWrite},
    {0x580b, 0x63,"",eReadWrite},
    {0x580c, 0x1a,"",eReadWrite},
    {0x580d, 0x05,"",eReadWrite},
    {0x580e, 0x1f,"",eReadWrite},
    {0x580f, 0x05,"",eReadWrite},
    {0x5810, 0x03,"",eReadWrite},
    {0x5811, 0x0c,"",eReadWrite},
    {0x5812, 0x02,"",eReadWrite},
    {0x5813, 0x5e,"",eReadWrite},
    {0x5814, 0x18,"",eReadWrite},
    {0x5815, 0x05,"",eReadWrite},
    {0x5816, 0x19,"",eReadWrite},
    {0x5817, 0x05,"",eReadWrite},
    {0x5818, 0x0d,"",eReadWrite},
    {0x5819, 0x40,"",eReadWrite},
    {0x581a, 0x04,"",eReadWrite},
    {0x581b, 0x0c,"",eReadWrite},
    {0x3106, 0x21,"",eReadWrite},
    {0x3a03, 0x4c,"",eReadWrite},
    {0x3a04, 0x40,"",eReadWrite},
    {0x3503, 0x00,"",eReadWrite},
    //{0x0100, 0x01,"",eReadWrite},
	
    {0x0000 ,0x00,"eTableEnd",eTableEnd}

};

const IsiRegDescription_t OV2686_g_svga[] =
{

    {0x370a, 0x23,"",eReadWrite},
    {0x3808, 0x03,"",eReadWrite},
    {0x3809, 0x20,"",eReadWrite},
    {0x380a, 0x02,"",eReadWrite},
    {0x380b, 0x58,"",eReadWrite},
    {0x3810, 0x00,"",eReadWrite},
    {0x3811, 0x04,"",eReadWrite},
    {0x3812, 0x00,"",eReadWrite},
    {0x3813, 0x04,"",eReadWrite},
    {0x3814, 0x31,"",eReadWrite},
    {0x3815, 0x31,"",eReadWrite},
    {0x3086, 0x01,"",eReadWrite},
    {0x380c, 0x06,"",eReadWrite},
    {0x380d, 0xa4,"",eReadWrite},
    {0x380e, 0x05,"",eReadWrite},
    {0x380f, 0x0e,"",eReadWrite},
    {0x3820, 0xc2,"",eReadWrite},
    {0x3821, 0x01,"",eReadWrite},
    {0x3a06, 0x00,"",eReadWrite},
    {0x3a07, 0xc2,"",eReadWrite},
    {0x3a08, 0x00,"",eReadWrite},
    {0x3a09, 0xa1,"",eReadWrite},
    {0x3a0e, 0x02,"",eReadWrite},
    {0x3a0f, 0x46,"",eReadWrite},
    {0x3a10, 0x02,"",eReadWrite},
    {0x3a11, 0x84,"",eReadWrite},
    {0x3a0a, 0x07,"",eReadWrite},
    {0x3a0b, 0x8c,"",eReadWrite},
    {0x3a0c, 0x07,"",eReadWrite},
    {0x3a0d, 0x8c,"",eReadWrite},
    {0x4008, 0x00,"",eReadWrite},
    {0x4009, 0x03,"",eReadWrite},
    {0x3503, 0x00,"",eReadWrite},
    {0x3a00, 0x43,"",eReadWrite},
	
    {0x0000 ,0x00,"eTableEnd",eTableEnd}
};

const IsiRegDescription_t OV2686_g_1600x1200[] =
{
    {0x3503, 0x03,"",eReadWrite},
    {0x3a00, 0x41,"",eReadWrite},
    {0x370a, 0x21,"",eReadWrite},
    {0x3808, 0x06,"",eReadWrite},
    {0x3809, 0x40,"",eReadWrite},
    {0x380a, 0x04,"",eReadWrite},
    {0x380b, 0xb0,"",eReadWrite},
    {0x3810, 0x00,"",eReadWrite},
    {0x3811, 0x08,"",eReadWrite},
    {0x3812, 0x00,"",eReadWrite},
    {0x3813, 0x08,"",eReadWrite},
    {0x3814, 0x11,"",eReadWrite},
    {0x3815, 0x11,"",eReadWrite},
    {0x3086, 0x01,"",eReadWrite},
    {0x380c, 0x06,"",eReadWrite},
    {0x380d, 0xa4,"",eReadWrite},
    {0x380e, 0x05,"",eReadWrite},
    {0x380f, 0x0e,"",eReadWrite},
    {0x3820, 0xc0,"",eReadWrite},
    {0x3821, 0x00,"",eReadWrite},
    {0x3a06, 0x00,"",eReadWrite},
    {0x3a07, 0xc2,"",eReadWrite},
    {0x3a08, 0x00,"",eReadWrite},
    {0x3a09, 0xa1,"",eReadWrite},
    {0x3a0e, 0x04,"",eReadWrite},
    {0x3a0f, 0x8c,"",eReadWrite},
    {0x3a10, 0x05,"",eReadWrite},
    {0x3a11, 0x08,"",eReadWrite},
    {0x4008, 0x02,"",eReadWrite},
    {0x4009, 0x09,"",eReadWrite},

    {0x0000 ,0x00,"eTableEnd",eTableEnd}

};


